package com.leaf.spring.y201907.day19.zk;

import java.util.concurrent.CountDownLatch;

import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.data.Stat;

public class ZookeeperConnectionTest {

	public static CountDownLatch countDownLatch = new CountDownLatch(1);

	public static void main(String[] args) throws Exception {

		ZookeeperWatcher watcher = new ZookeeperWatcher();

//		final ZooKeeper zk = new ZooKeeper("192.168.90.49:2181", 5000, watcher);
		final ZooKeeper zk = new ZooKeeper("192.168.89.80:2181", 5000, watcher);

		new Thread(() -> {
			System.out.print("等待连接中");
			while (!ZookeeperWatcher.isConnected) {
				try {
					System.out.print("。");
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println("开始遍历节点");
			new ZookeeperOperator(zk).iteratorChild("/");
			countDownLatch.countDown();
		}).start();

		countDownLatch.await();
		
		Stat stat = zk.exists("/shfft", false);
		System.out.println(stat);

		System.out.println("over =========");

	}

}
